﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace WindowsFormsApplication3
{
    class DriverPaymentTransaction
    {
          private String connString = Program.ConnStr;
        public  driverpaymentbean  driverpaymentbean = null;
        public  driverpaymentbean getpaymentbyjobcode(String jobcode)
        {
             driverpaymentbean = null;

           try
            {


            

                OleDbConnection oledbconnnection = new OleDbConnection(connString);
                oledbconnnection.Open();


                String query = "Select * from driverpaymentmastertable WHERE jobcode ='"+jobcode+"' ";
                OleDbCommand oledbcomand = new OleDbCommand(query, oledbconnnection);
                OleDbDataReader reader = oledbcomand.ExecuteReader();
                
                if (reader.Read())
                {

                    Console.WriteLine("Error at Database in getpaymentbyjobcode" );
                     driverpaymentbean = new  driverpaymentbean();

                     driverpaymentbean.Paymentpk = reader.GetInt32(0);
                     driverpaymentbean.Jobcode = reader.GetString(1);
                     driverpaymentbean.Acceptorname = reader.GetString(2);

                     driverpaymentbean.Amount = reader.GetInt32(3);
                     driverpaymentbean.Chequeno = reader.GetString(4);
                     driverpaymentbean.Chequereleasedate = reader.GetDateTime(5);
                     driverpaymentbean.Chequedate = reader.GetDateTime(6);
                     driverpaymentbean.Postdate = reader.GetDateTime(7);

                     driverpaymentbean.Ischequeselected = reader.GetBoolean(8);
                     driverpaymentbean.Iscashselected = reader.GetBoolean(9);
                     driverpaymentbean.Description1 = reader.GetString(10);
                     driverpaymentbean.Vehicleno = reader.GetString(11);

                    if ( driverpaymentbean.Ischequeselected)
                    {

                    }



                }



                reader.Close();
                oledbconnnection.Close();
           }
           catch (Exception exp)
            {
               Console.WriteLine("Error at Database in getpaymentbyjobcode" + exp);

            }
            finally
            {

            }

            return  driverpaymentbean;
        }
        public String newinvoiceget()
        {
            String jobcodeno = null;
          

                Int32 S = 0;
                //  lblinvoice.Text = "";
                OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(Program.ConnStr);
                oleDbConnection1.Open();


                String query = "SELECT TOP 1 paymentpk FROM driverpaymentmastertable ORDER BY paymentpk DESC";
                OleDbDataAdapter dAdapter = new OleDbDataAdapter(query, Program.ConnStr);


                DataSet ds = new DataSet();

                dAdapter.Fill(ds, "tblpaypk");
                if (ds.Tables[0].Rows.Count == 0)
                {
                    S = 0;
                }
                else
                {
                    S = int.Parse(ds.Tables[0].Rows[0][0].ToString());
                }

                S++;

                jobcodeno = "DINV#0" + S.ToString();

                //   lblinvoice.Text = "CINV#0" + S.ToString();
                //  lblinvoice.Enabled = false;

           

                //  MessageBox.Show("Failed to autogenerate INVOICE ");
                //  MessageBox.Show(exp.ToString());
                //  this.Close();
           



            return jobcodeno;


        }


    }
}
